<?php defined('SYSPATH') or die('No direct access allowed.');

class Model_Supplier_Gallery extends ORM
{
    public static function save_gallery($params, $group_name)
    {
        if($params['group_id']){
            $pid = $params['group_id'];
        }else{
            $pid = DB::select()->from('image_group')
                ->where('group_name','=',$group_name)
                ->execute()->get('group_id');
        }
        $data = [
            'pid'            => $pid,
            'group_name'     => $params['photo_name'],
            'description'    => "供应商成员ID:{$params['supplier_id']}的相册",
            'do_not'         => '1',
            'level'          => $params['level'],
            'status'         => 1,
            'belong_type'    => 1,
            'belong_type_id' => $params['supplier_id']
        ];

        $id = DB::insert('image_group', array_keys($data))->values(array_values($data))->execute();
        return [
            'status'     => true,
            'group_id'   => $id[0],
            'group_name' => $params['photo_name']
        ];
    }
}